swadhinbiswas feat: optimize Docker CI/CD builds, refine site-wide UI aesthetic, and remediate secrets · 8/19/2026
c3e5c18
283 lines · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
---
import BaseLayout from "../../../../layouts/BaseLayout.astro";
import { Header } from "../../../../components/layout/Header";
import { Card, CardContent, CardHeader, CardTitle } from "../../../../components/ui/card";
import { Button } from "../../../../components/ui/button";
import { Badge } from "../../../../components/ui/badge";
import { 
  Star, 
  GitFork, 
  Copy, 
  ExternalLink, 
  Code, 
  BookOpen, 
  ArrowLeft, 
  Terminal, 
  Globe, 
  Check,
  ShieldAlert,
  Server
} from "lucide-react";
import { verifyToken } from "../../../../lib/auth";
import { getDb } from "../../../../lib/db";
import { eq, and } from "drizzle-orm";
import { cachedRepos, instances, stars } from "../../../../lib/db/schema";

const token = Astro.cookies.get("community_session")?.value;
const user = token ? await verifyToken(token) : null;
const { instance, owner, repo } = Astro.params;
const fullName = `${owner}/${repo}`;

const db = getDb() as any;

// Find the instance first
const instanceData = await db.query.instances.findFirst({
  where: eq(instances.name, instance as string)
}).catch(() => null);

// Then find the repo
let repoData = null;
if (instanceData) {
  repoData = await db.query.cachedRepos.findFirst({
    where: and(
      eq(cachedRepos.instanceId, instanceData.id),
      eq(cachedRepos.fullName, fullName)
    )
  }).catch(() => null);
}

// Check if current user has starred this repo
let isStarred = false;
if (user && repoData) {
  const existingStar = await db.query.stars.findFirst({
    where: and(
      eq(stars.userId, user.sub),
      eq(stars.repoId, repoData.id)
    )
  }).catch(() => null);
  isStarred = !!existingStar;
}

const starCount = repoData?.starCount ?? 0;
const forkCount = repoData?.forkCount ?? 0;
const httpCloneUrl = repoData?.httpCloneUrl ?? `https://${instance}/${fullName}.git`;
const language = repoData?.language ?? "Unknown";
const description = repoData?.description ?? "No description provided.";
---
<BaseLayout title={`${fullName} — OpenCodeHub Community`}>
  <Header client:load user={user} />
  
  <main class="container px-4 sm:px-8 py-8 sm:py-12 space-y-8 max-w-5xl mx-auto">
    
    <!-- Breadcrumbs -->
    <div class="flex items-center gap-2 text-xs text-muted-foreground flex-wrap">
      <a href="/explore" class="hover:text-foreground">Explore</a>
      <span>/</span>
      {instanceData ? (
        <a href={`/instances/${instanceData.id}`} class="hover:text-foreground flex items-center gap-1">
          <Server className="h-3 w-3 text-primary" />
          {instance}
        </a>
      ) : (
        <span>{instance}</span>
      )}
      <span>/</span>
      <a href={`/u/${owner}`} class="hover:text-foreground">@{owner}</a>
      <span>/</span>
      <span class="text-foreground font-semibold">{repo}</span>
    </div>

    <!-- Repository Header -->
    <div class="rounded-3xl border border-border/60 bg-card/60 backdrop-blur-xl p-6 sm:p-8 space-y-6">
      <div class="flex flex-col sm:flex-row sm:items-start justify-between gap-4">
        <div class="space-y-2">
          <div class="flex items-center gap-3 flex-wrap">
            <h1 class="text-2xl sm:text-3xl font-extrabold tracking-tight text-foreground flex items-center gap-2">
              <BookOpen className="h-7 w-7 text-primary shrink-0" />
              {fullName}
            </h1>
            <Badge variant="outline" className="text-xs uppercase font-semibold">
              {repoData?.visibility || "public"}
            </Badge>
          </div>

          <p class="text-sm sm:text-base text-muted-foreground max-w-2xl leading-relaxed">
            {description}
          </p>
        </div>

        <!-- Action Buttons -->
        <div class="flex items-center gap-2 shrink-0">
          <Button 
            id="star-btn"
            variant="outline" 
            size="sm" 
            className={`gap-1.5 text-xs font-semibold ${isStarred ? "bg-amber-500/15 text-amber-400 border-amber-500/40" : ""}`}
            data-repo-id={repoData?.id} 
            data-full-name={fullName}
          >
            <Star className={`h-4 w-4 ${isStarred ? "text-amber-400 fill-amber-400" : "text-amber-400"}`} />
            <span id="star-label">{isStarred ? "Starred" : "Star"}</span>
          </Button>

          <a href={`${instanceData?.siteUrl || `https://${instance}`}/${fullName}`} target="_blank" rel="noreferrer">
            <Button size="sm" className="gap-1.5 text-xs font-semibold bg-primary hover:bg-primary/90">
              <ExternalLink className="h-3.5 w-3.5" />
              View Origin
            </Button>
          </a>
        </div>
      </div>

      <!-- Quick Git Clone Bar -->
      <div class="rounded-xl border border-border/60 bg-muted/30 p-3 flex items-center justify-between gap-3 text-xs">
        <div class="flex items-center gap-2 text-muted-foreground font-mono overflow-x-auto">
          <Terminal className="h-4 w-4 text-primary shrink-0" />
          <span class="text-foreground shrink-0 select-all font-medium">git clone {httpCloneUrl}</span>
        </div>
        <button 
          id="copy-clone-btn"
          class="shrink-0 inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-card border border-border/60 hover:bg-accent text-foreground text-xs font-medium transition-colors"
          data-clone-url={`git clone ${httpCloneUrl}`}
        >
          <Copy className="h-3.5 w-3.5" />
          <span>Copy</span>
        </button>
      </div>
    </div>

    <!-- Main Content & Sidebar -->
    <div class="grid lg:grid-cols-3 gap-8">
      
      <!-- Left: Instructions & Docs -->
      <div class="lg:col-span-2 space-y-6">
        <Card className="border-border/60 bg-card/50">
          <CardHeader>
            <CardTitle className="text-base flex items-center gap-2">
              <BookOpen className="h-4 w-4 text-primary" />
              About This Federated Project
            </CardTitle>
          </CardHeader>
          <CardContent className="space-y-4 text-sm text-muted-foreground leading-relaxed">
            <p>
              This repository is hosted natively on the <b>{instance}</b> node and aggregated to the community catalog via federated metadata caching.
            </p>
            <p>
              To browse source files, commits, issues, and pull requests directly, click the <b>View Origin</b> button above to visit the home node.
            </p>
          </CardContent>
        </Card>

        <!-- Contribution Card -->
        <Card className="border-border/60 bg-card/50">
          <CardHeader>
            <CardTitle className="text-base flex items-center gap-2">
              <GitFork className="h-4 w-4 text-indigo-400" />
              How to Fork &amp; Contribute
            </CardTitle>
          </CardHeader>
          <CardContent className="space-y-3 text-xs sm:text-sm text-muted-foreground leading-relaxed">
            <ol class="space-y-2.5 list-decimal list-inside">
              <li>Clone the repository using standard Git: <code class="bg-muted px-1.5 py-0.5 rounded font-mono text-xs">git clone {httpCloneUrl}</code></li>
              <li>Make your changes locally and commit them to a new branch.</li>
              <li>Push the branch to your own self-hosted OpenCodeHub node.</li>
              <li>Submit a cross-node federated pull request to <code class="bg-muted px-1.5 py-0.5 rounded font-mono text-xs">@{owner}</code>.</li>
            </ol>
          </CardContent>
        </Card>
      </div>

      <!-- Right: Meta Info -->
      <div class="space-y-6">
        <Card className="border-border/60 bg-card/50">
          <CardContent className="p-5 space-y-4">
            <h3 class="text-sm font-bold text-foreground">Project Details</h3>
            
            <div class="space-y-3 text-xs">
              <div class="flex justify-between items-center py-1 border-b border-border/40">
                <span class="text-muted-foreground flex items-center gap-1.5"><Code className="h-3.5 w-3.5 text-primary" /> Primary Language</span>
                <span class="font-semibold text-foreground">{language}</span>
              </div>
              <div class="flex justify-between items-center py-1 border-b border-border/40">
                <span class="text-muted-foreground flex items-center gap-1.5"><Star className="h-3.5 w-3.5 text-amber-400" /> Stars</span>
                <span class="font-semibold text-foreground">{starCount}</span>
              </div>
              <div class="flex justify-between items-center py-1 border-b border-border/40">
                <span class="text-muted-foreground flex items-center gap-1.5"><GitFork className="h-3.5 w-3.5" /> Forks</span>
                <span class="font-semibold text-foreground">{forkCount}</span>
              </div>
              <div class="flex justify-between items-center py-1">
                <span class="text-muted-foreground flex items-center gap-1.5"><Server className="h-3.5 w-3.5 text-purple-400" /> Host Node</span>
                <span class="font-semibold text-foreground">{instance}</span>
              </div>
            </div>

            <div class="pt-2">
              <a href={`${instanceData?.siteUrl || `https://${instance}`}/${fullName}`} target="_blank" rel="noreferrer" class="w-full block">
                <Button variant="outline" className="w-full text-xs gap-1.5">
                  <ExternalLink className="h-3.5 w-3.5" />
                  Open on {instance}
                </Button>
              </a>
            </div>
          </CardContent>
        </Card>

        <!-- Social Disclaimer -->
        <div class="rounded-2xl border border-border/60 bg-muted/20 p-4 text-[11px] text-muted-foreground leading-relaxed space-y-1">
          <div class="font-semibold text-foreground">Community Social Actions:</div>
          <p>
            Stars registered on this hub are stored in the federated catalog. To star directly on the origin server, sign into that node.
          </p>
        </div>
      </div>

    </div>
  </main>

  <script>
    import { toast } from "sonner";

    // Copy Clone command
    const copyBtn = document.getElementById('copy-clone-btn');
    copyBtn?.addEventListener('click', () => {
      const text = copyBtn.dataset.cloneUrl || "";
      navigator.clipboard.writeText(text);
      toast.success("Command copied to clipboard!");
    });

    // Star Toggle
    const starBtn = document.getElementById('star-btn');
    const starLabel = document.getElementById('star-label');

    starBtn?.addEventListener('click', async () => {
      const repoId = starBtn.dataset.repoId;
      const fullName = starBtn.dataset.fullName;

      try {
        const res = await fetch('/api/stars', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ repoId, fullName })
        });
        const data = await res.json();
        
        if (data.success) {
          const starred = data.data?.starred;
          if (starLabel) starLabel.textContent = starred ? "Starred" : "Star";
          starBtn.classList.toggle("bg-amber-500/15", starred);
          starBtn.classList.toggle("text-amber-400", starred);
          starBtn.classList.toggle("border-amber-500/40", starred);
          toast.success(starred ? `Starred ${fullName}` : `Unstarred ${fullName}`);
        } else if (res.status === 401) {
          toast.error("Please sign in to star repositories");
        } else {
          toast.error(data.error || "Failed to update star");
        }
      } catch (err) {
        toast.error("Network error");
      }
    });
  </script>
</BaseLayout>